{include file="public/header" /}
<span class="layui-breadcrumb">
	<a href="javascript:;">其他</a>
	<a><cite>搜索信息</cite></a>
</span>
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-body">
			<div style="color:#FF5722">搜索数据默认展示为当前月份数据</div>
			<div class="layui-form">
				<div style="width:48%;float:left;margin-top:10px">
					<div>回撤搜索结果：</div>
					<div class="layui-inline" style="padding:2px">
						<label class="layui-form-label">请选择范围</label>
						<div class="layui-input-inline" style="min-width:380px">
							<input type="text" class="layui-input" id="rang2" placeholder="开始 到 结束"  autocomplete="off" >
						</div>
						<button type='button' class="layui-btn" onclick="searrang2()">搜索</button>
					</div>
					<div style="padding:5px;cursor: pointer;border:1px solid #dddddd;height:20px;background-color: #f0f0f0;border-bottom:none;"><i title="导出" class="layui-icon layui-icon-export" style="font-size: 24px;float: right;width:24px;height:24px;" onclick="daochu('rang2','回撤搜索结果','搜索次数','搜索结果','1')"></i></div>
					<div style="clear:both"></div>
					<table class="layui-hide" id="test2" lay-filter="test"></table>
				</div>
				<div style="width:48%;float: right;margin-top:10px">
					<div>搜索无结果排名：</div>
					<div class="layui-inline" style="padding:2px">
						<label class="layui-form-label">请选择范围</label>
						<div class="layui-input-inline" style="min-width:380px">
							<input type="text" class="layui-input" id="rang3" placeholder="开始 到 结束"  autocomplete="off" >
						</div>
						<button type='button' class="layui-btn" onclick="searrang3()">搜索</button>
					</div>
					<div style="padding:5px;cursor: pointer;border:1px solid #dddddd;height:20px;background-color: #f0f0f0;border-bottom:none;"><i title="导出" class="layui-icon layui-icon-export" style="font-size: 24px;float: right;width:24px;height:24px;" onclick="daochu('rang3','搜索内容','搜索次数','搜索无结果','2')"></i></div>
					<div style="clear:both"></div>
					<table class="layui-hide" id="test3" lay-filter="test"></table>
				</div>
				<div style="width:48%;float:left;margin-top:10px">
					<div>预览页左侧点击数据：</div>
					<div class="layui-inline" style="padding:2px">
						<label class="layui-form-label">请选择范围</label>
						<div class="layui-input-inline" style="min-width:380px">
							<input type="text" class="layui-input" id="rang" placeholder="开始 到 结束"  autocomplete="off" >
						</div>
						<button type='button' class="layui-btn" onclick="searrang()">搜索</button>
					</div>
					<div style="padding:5px;cursor: pointer;border:1px solid #dddddd;height:20px;background-color: #f0f0f0;border-bottom:none;"><i title="导出" class="layui-icon layui-icon-export" style="font-size: 24px;float: right;width:24px;height:24px;" onclick="daochu('rang','点击内容','点击次数','预览页左侧点击','3')"></i></div>
					<div style="clear:both"></div>
					<table class="layui-hide" id="test" lay-filter="test"></table>
				</div>
				<div style="width:48%;float:right;margin-top:10px">
					<div>预览页右侧点击数据：</div>
					<div class="layui-inline" style="padding:2px">
						<label class="layui-form-label">请选择范围</label>
						<div class="layui-input-inline" style="min-width:380px">
							<input type="text" class="layui-input" id="rang1" placeholder="开始 到 结束" autocomplete="off"  >
						</div>
						<button type='button' class="layui-btn" onclick="searrang1()">搜索</button>
					</div>
					<div style="padding:5px;cursor: pointer;border:1px solid #dddddd;height:20px;background-color: #f0f0f0;border-bottom:none;"><i title="导出" class="layui-icon layui-icon-export" style="font-size: 24px;float: right;width:24px;height:24px;" onclick="daochu('rang1','点击内容','点击次数','预览页右侧点击','4')"></i></div>
					<div style="clear:both"></div>
					<table class="layui-hide" id="test1" lay-filter="test"></table>
				</div>

				
				<div style="clear: both;"></div>

			</div>

		</div>
	</div>
</div>

{include file="/public/footer" /}
<script>
	var table
	var laydate

	function searrang2() {
		var rang2 = $('#rang2').val();
		if (rang2 == '') {
			var start = '';
			var end = '';
		}else{
            var start = $.trim($.trim(rang2.split("to")[0]));
		    var end =$.trim($.trim(rang2.split("to")[1]));
		    var h =$.trim($.trim(end.split(" ")[1]));
		    if(h=='00:00:00'){
		      var q =$.trim($.trim(end.split(" ")[0]));
              end=q+' '+"23:59:59";
		    }
		}
		
		table.reload('test2', {
			url: '/admin/Searchcount/get_all/',
			where: { //设定异步数据接口的额外参数，任意设
				'start': start ,'end': end
			 },
		}); 
	}
	function searrang3() {
		var rang3 = $('#rang3').val();
		if (rang3 == '') {
			var start = '';
			var end = '';
		}else{
            var start = $.trim($.trim(rang3.split("to")[0]));
		    var end =$.trim($.trim(rang3.split("to")[1]));
		    var h =$.trim($.trim(end.split(" ")[1]));
		    if(h=='00:00:00'){
		      var q =$.trim($.trim(end.split(" ")[0]));
              end=q+' '+"23:59:59";
		    }
		}

		table.reload('test3', {
			url: '/admin/Searchcount/get_all_null/',
			where: { //设定异步数据接口的额外参数，任意设
				'start': start ,'end': end
			 },
		}); 
	}
	function searrang() {
		var rang = $('#rang').val();
		if (rang == '') {
			var start = '';
			var end = '';
		}else{
            var start = $.trim($.trim(rang.split("to")[0]));
		    var end =$.trim($.trim(rang.split("to")[1]));
		    var h =$.trim($.trim(end.split(" ")[1]));
		    if(h=='00:00:00'){
		      var q =$.trim($.trim(end.split(" ")[0]));
              end=q+' '+"23:59:59";
		    }
		}

		table.reload('test', {
			url: '/admin/Searchcount/get_preview_click/',
			where: { //设定异步数据接口的额外参数，任意设
				'start': start ,'end': end
			 },
		}); 
	}
	function searrang1() {
		var rang1 = $('#rang1').val();
		if (rang1 == '') {
			var start = '';
			var end = '';
		}else{
            var start = $.trim($.trim(rang1.split("to")[0]));
		    var end =$.trim($.trim(rang1.split("to")[1]));
		    var h =$.trim($.trim(end.split(" ")[1]));
		    if(h=='00:00:00'){
		      var q =$.trim($.trim(end.split(" ")[0]));
              end=q+' '+"23:59:59";
		    }

		}

		table.reload('test1', {
			url: '/admin/Searchcount/get_result_click/',
			where: { //设定异步数据接口的额外参数，任意设
				'start': start ,'end': end
			 },
		}); 
	}

	


	layui.use(['table', 'laydate'], function() {
		table = layui.table;
		laydate = layui.laydate;
		
		table.render({
			elem: '#test',
			url: '/admin/Searchcount/get_preview_click/',
			title: '预览页左侧点击数据',
			cols: [
					[{
						field: 'leftclick',
						title: '点击产品'
					}, {
						field: 'b',
						title: '点击次数'
					}
					, {
							field: 'det',
							title: '详细'
						}
					]
				]
		
				,
			page: true,
			height: 470
		});

	
		
		table.render({
			elem: '#test1',
			url: '/admin/Searchcount/get_result_click/',
			title: '结果页点击数据',
			cols: [
					[{
						field: 'rightclick',
						title: '点击产品'
					}, {
						field: 'b',
						title: '点击次数'
					}
					, {
							field: 'det',
							title: '详细'
						}
					]
				]
		
				,
			page: true,
			height: 470
		});
		
		table.render({
			elem: '#test2',
			url: '/admin/Searchcount/get_all/',
			title: '搜索结果排名',

			cols: [
					[{
							field: 'sou',
							title: '搜索内容'
						}

						, {
							field: 'b',
							title: '搜索次数'
						}

						, {
							field: 'det',
							title: '详细'
						}
					]
				]

				,
			page: true,
			height: 470
		});


		table.render({
			elem: '#test3',
			url: '/admin/Searchcount/get_all_null/',
			title: '搜索无结果排名',
			cols: [
					[{
							field: 'noresult',
							title: '搜索内容'
						}

						, {
							field: 'b',
							title: '搜索次数'
						}

						, {
							field: 'det',
							title: '详细'
						}
					]
				]

				,
			page: true,
			height: 470
		});

		laydate.render({
			elem: '#rang',
			type: 'datetime',
			range: 'to',
			format: 'yyyy-MM-dd HH:mm:ss'
		});
		laydate.render({
			elem: '#rang1',
			type: 'datetime',
			range: 'to',
			format: 'yyyy-MM-dd HH:mm:ss'
		});
		laydate.render({
			elem: '#rang2',
			type: 'datetime',
			range: 'to',
			format: 'yyyy-MM-dd HH:mm:ss'
		});
		laydate.render({
			elem: '#rang3',
			type: 'datetime',
			range: 'to',
			format: 'yyyy-MM-dd HH:mm:ss'
		});
		laydate.render({
			elem: '#weidu',
			type: 'datetime',
			range: 'to',
			format: 'yyyy-MM-dd HH:mm:ss'
		});
	});
	function daochu(id,field1,field2,title,t){
		layer.load();
		var rang = $('#'+id).val();
		if (rang == '') {
			var start = '';
			var end = '';
		}else{
            var start = $.trim($.trim(rang.split("to")[0]));
		    var end =$.trim($.trim(rang.split("to")[1]));
		    var h =$.trim($.trim(end.split(" ")[1]));
		    if(h=='00:00:00'){
		      var q =$.trim($.trim(end.split(" ")[0]));
              end=q+' '+"23:59:59";
		    }
		    
		}

		$.post("{:url('Searchcount/daochu')}",{start:start,end:end,t:t},function(res){
			//console.log(res);
			var str='';
			for (var i =0; i<res.data.length; i++) {
				for (var j = 0; j < res.data[i].length; j++) {
					if(j>0){
                       str+=res.data[i][j]+",";
					}else{
					   str+="'"+res.data[i][j]+"',";
					}
					
				}
				str+='\n';
			}
			var tit=field1+','+field2;
			str=tit+'\n'+str;
			var uri='data:text/csv;charset=utf-8,\ufeff'+encodeURIComponent(str);
			var link=document.createElement('a');
			link.href=uri;
			link.download=title+'.csv';
			document.body.appendChild(link);
			link.click();
			document.body.removeChild(link);
            layer.closeAll('loading');
			//console.log(str);
	       
       }) 
		
 
	}
</script>
